﻿using System.Collections.Generic;
using Interface;

namespace Model
{
    public class OperatorCollection //Tien - 13. maj
    {
        public List<Operator> OperatorCol { get; set; }

        public OperatorCollection()
        {
            OperatorCol = new List<Operator>();
        }

        #region Methods
        /// <summary>
        /// Add operator to list
        /// </summary>
        /// <param name="initials">string, initials consisting of three letters</param>
        /// <param name="password">string, password</param>
        /// <returns></returns>
        public Operator Add(string initials, string password, bool isEnabled) //29. maj
        {
            Operator _operator = new Operator(initials, password, isEnabled);
            OperatorCol.Add(_operator);
            return _operator;
        }
        /// <summary>
        /// Edit password for operator by operator object
        /// </summary>
        /// <param name="op">IOperator object to change password</param>
        /// <param name="password">string, new password</param>
        /// <param name="isEnabled"></param>
        /// <returns>Operator, returns object of newly changed operator</returns>
        public Operator Edit(IOperator op, string password, bool isEnabled) 
        {
            int i = FindIndex(op);
            OperatorCol[i].Password = password;
            OperatorCol[i].IsEnabled = isEnabled;
            return OperatorCol[i];
        }
        /// <summary>
        /// Find operator by initials
        /// </summary>
        /// <param name="initials">string initials</param>
        /// <returns>Return operator object</returns>
        public IOperator Find(string initials) 
        {
            foreach (Operator op in OperatorCol)
            {
                if (Equals(op.Initials, initials))
                    return (IOperator)op;
            }
            return null;
        }
        /// <summary>
        /// Find operator index by an operator object
        /// </summary>
        /// <param name="op">IOperator</param>
        /// <returns>int index</returns>
        public int FindIndex(IOperator op) 
        {
            int i = 0;
            foreach (Operator o in OperatorCol)
            {
                if (Equals(o, op))
                    return i;
                i++;
            }
            return -1;
        }
        /// <summary>
        /// Find operator index by initials
        /// </summary>
        /// <param name="op">string intials</param>
        /// <returns>int index</returns>
        public int FindIndex(string initials) 
        {
            int i = 0;
            foreach (Operator o in OperatorCol)
            {
                if (Equals(o.Initials, initials))
                    return i;
                i++;

            }
            return -1;
        }
        /// <summary>
        /// Remove operator in list by object
        /// </summary>
        /// <param name="op">Ioperator</param>
        public void Remove(IOperator op)
        {
            OperatorCol.Remove((Operator)op);
        }
        #endregion
    }
}